package com.mapapp.flutter_mapapp.persenter;

import android.content.Context;

import com.mapapp.flutter_mapapp.http.ActivityLifeCycleEvent;
import com.mapapp.flutter_mapapp.http.Api;
import com.mapapp.flutter_mapapp.http.HttpUtil;
import com.mapapp.flutter_mapapp.http.ProgressSubscriber;
import com.mapapp.flutter_mapapp.util.ToastUtils;
import com.mapapp.flutter_mapapp.view.SeparateHouseholdViewInterface;

import rx.subjects.PublishSubject;

public class SeparateHouseholdPresenter {
    private Context mContext;
    private SeparateHouseholdViewInterface mView;
    private PublishSubject<ActivityLifeCycleEvent> lifecycleSubject;

    public SeparateHouseholdPresenter(SeparateHouseholdViewInterface view, Context context, PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        this.mView = view;
        this.mContext = context;
        this.lifecycleSubject = lifecycleSubject;
    }

    public void submitSplitRegion(final String masterId,
                                  int number,
                                  String message,
                                  String radioName,
                                  String photoFolderName) {
        HttpUtil.getInstance().toSubscribe(Api.getApiService().submitSplitRegion(masterId, number, message, radioName, photoFolderName),
                new ProgressSubscriber<String>(mContext, false) {
                    @Override
                    protected void _onNext(String s) {
                        ToastUtils.showMessage(mContext, "操作成功");
                        mView.submitProcessStatus(true, masterId);
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.submitProcessStatus(false, masterId);
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }


    public void submitProcess(String comment,
                              String endTime,
                              String photoFolderName,
                              String processId,
                              String radioName,
                              final String regionId,
                              String startTime,
                              int state,
                              int type) {
        HttpUtil.getInstance().toSubscribe(Api.getApiService().submitProcess(comment, endTime, photoFolderName, processId, radioName, regionId, startTime, state, type),
                new ProgressSubscriber<String>(mContext, false) {
                    @Override
                    protected void _onNext(String processBeans) {
                        mView.submitProcessStatus(true, regionId);
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.submitProcessStatus(false, regionId);
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);

    }

    public void submitProcessNoDialog(String comment,
                                      String endTime,
                                      String photoFolderName,
                                      String processId,
                                      String radioName,
                                      final String regionId,
                                      String startTime,
                                      int state,
                                      int type) {
        HttpUtil.getInstance().toSubscribeNoDialog(Api.getApiService().submitProcess(comment, endTime, photoFolderName, processId, radioName, regionId, startTime, state, type),
                new ProgressSubscriber<String>(mContext, false) {
                    @Override
                    protected void _onNext(String processBeans) {
                        mView.submitProcessStatus(true, regionId);
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.submitProcessStatus(false, regionId);
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);

    }

    public void submitSplitRegionNoDialog(final String masterId,
                                          int number,
                                          String message,
                                          String radioName,
                                          String photoFolderName) {
        HttpUtil.getInstance().toSubscribeNoDialog(Api.getApiService().submitSplitRegion(masterId, number, message, radioName, photoFolderName),
                new ProgressSubscriber<String>(mContext, false) {
                    @Override
                    protected void _onNext(String s) {
                        mView.submitProcessStatus(true, masterId);
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.submitProcessStatus(false, masterId);
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }

    public void submitMergeRegionNoDialog(final String masterId,
                                          String ids,
                                          String message,
                                          String radioName,
                                          String photoFolderName) {
        HttpUtil.getInstance().toSubscribeNoDialog(Api.getApiService().submitMergeRegion(masterId, ids, message, radioName, photoFolderName),
                new ProgressSubscriber<String>(mContext, false) {
                    @Override
                    protected void _onNext(String s) {
                        mView.submitProcessStatus(true, masterId);
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.submitProcessStatus(false, masterId);
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }

    public void submitOperateInfo(String type, String regionId, String processId, String fixType) {
        HttpUtil.getInstance().toSubscribeNoDialog(Api.getApiService().submitOperateInfo(type, regionId, processId, fixType),
                new ProgressSubscriber<Object>(mContext, false) {
                    @Override
                    protected void _onNext(Object s) {
                    }

                    @Override
                    protected void _onError(String message) {
                    }
                }, lifecycleSubject);
    }
}
